﻿#include "StepInfoDialog.h"
#include "DataTrans.h"


StepInfoDialog::StepInfoDialog(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);	

	QStringList strListHeader;
	strListHeader << tr("通道属性") << tr("通道状态") << tr("通道属性") << tr("通道状态") << tr("通道属性")
		<< tr("通道状态");	

	UiHelper::SetTable(ui.tableInfo, strListHeader);
	m_tableHelper.init(ui.tableStep);
}

StepInfoDialog::~StepInfoDialog()
{
}

void StepInfoDialog::showEvent(QShowEvent *event)
{
	updateTable();
	__super::showEvent(event);
}

void StepInfoDialog::updateTable()
{
	auto &step = record->info.stepInfo;
	
	//info
	ui.tableInfo->setRowCount(7);

	ui.tableInfo->setItem(0, 0, new QTableWidgetItem(tr("设备_单元_通道")));
	ui.tableInfo->setItem(0, 1, new QTableWidgetItem(QString::asprintf("%d-%02d",record->info.itemIndex / 8 + 1, record->info.itemIndex % 8 + 1)));
	
	ui.tableInfo->setItem(1, 0, new QTableWidgetItem(tr("启动时间")));
	ui.tableInfo->setItem(1, 1, new QTableWidgetItem(record->info.recordTime.toString("yyyy-MM-dd HH:mm:ss")));

	ui.tableInfo->setItem(2, 0, new QTableWidgetItem(tr("起始工步")));
	ui.tableInfo->setItem(2, 1, new QTableWidgetItem(QString::number(step.startStepIndex)));
	
	ui.tableInfo->setItem(3, 0, new QTableWidgetItem(tr("记录条件-时间")));	
	ui.tableInfo->setItem(4, 0, new QTableWidgetItem(tr("记录条件-电压")));	
	ui.tableInfo->setItem(5, 0, new QTableWidgetItem(tr("记录条件-电流")));	
	
	ui.tableInfo->setItem(0, 2, new QTableWidgetItem(tr("电压下限")));
	ui.tableInfo->setItem(1, 2, new QTableWidgetItem(tr("电压上限")));
	ui.tableInfo->setItem(2, 2, new QTableWidgetItem(tr("电流下限")));
	ui.tableInfo->setItem(3, 2, new QTableWidgetItem(tr("电流上限")));
	ui.tableInfo->setItem(4, 2, new QTableWidgetItem(tr("温度上限")));
	ui.tableInfo->setItem(5, 2, new QTableWidgetItem(tr("温度下限")));
	ui.tableInfo->setItem(6, 2, new QTableWidgetItem(tr("延迟时间")));	
	
	ui.tableInfo->setItem(0, 4, new QTableWidgetItem(tr("化成检测时间")));
	ui.tableInfo->setItem(1, 4, new QTableWidgetItem(tr("化成电压值")));

	if (step.step.stepList.size() > 0)
	{
		auto &stepInfo = step.step.stepList[0];
		//记录
		if(stepInfo.isRecordTimeIntervalVaild())
			ui.tableInfo->setItem(3, 1, new QTableWidgetItem(QString::number(stepInfo.RecordTimeInterval()/1000) + "s"));
		if (stepInfo.isRecordVoltageChangeVaild())
			ui.tableInfo->setItem(4, 1, new QTableWidgetItem(QString::number(stepInfo.RecordVoltageChange()) + "V"));
		if (stepInfo.isRecordCurrentChangeVaild())
			ui.tableInfo->setItem(5, 1, new QTableWidgetItem(QString::number(stepInfo.RecordCurrentChange()) + "A"));		

		//上下限
		if (stepInfo.isProtectVoltageLowerVaild())
			ui.tableInfo->setItem(0, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectVoltageLower(), 'f', 4) + "V"));

		if (stepInfo.isProtectVoltageUpperVaild())
			ui.tableInfo->setItem(1, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectVoltageUpper(), 'f', 4) + "V"));

		if (stepInfo.isProtectCurrentLowerVaild())
			ui.tableInfo->setItem(2, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectCurrentLower(), 'f', 4) + "A"));

		if (stepInfo.isProtectCurrentUpperVaild())
			ui.tableInfo->setItem(3, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectCurrentUpper(), 'f', 4) + "A"));

		if (stepInfo.isProtectTempatureLowerVaild())
			ui.tableInfo->setItem(4, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectTempatureLower(), 'f', 4) + "°C"));

		if (stepInfo.isProtectTempatureUpperVaild())
			ui.tableInfo->setItem(5, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectTempatureUpper(), 'f', 4) + "°C"));

		if (stepInfo.isProtectDelayTimeVaild())
			ui.tableInfo->setItem(6, 3, new QTableWidgetItem(QString::number(stepInfo.ProtectDelayTime()/1000) + "S"));

		if (stepInfo.isProtectDetalVolVaild())
			ui.tableInfo->setItem(0, 5, new QTableWidgetItem(QString::number(stepInfo.ProtectDetalVol(), 'f', 4) + "V"));

		if (stepInfo.isProtectDetalVolTimeVaild())
			ui.tableInfo->setItem(1, 5, new QTableWidgetItem(QString::number(stepInfo.ProtectDetalVolTime() / 1000) + "S"));		
	}


	ui.tableInfo->setItem(2, 4, new QTableWidgetItem(tr("电池批号")));
	ui.tableInfo->setItem(2, 5, new QTableWidgetItem(step.cellBatch));

	ui.tableInfo->setItem(3, 4, new QTableWidgetItem(tr("电池编号")));
	ui.tableInfo->setItem(3, 5, new QTableWidgetItem(step.cellNo));	

	ui.tableInfo->setItem(4, 4, new QTableWidgetItem(tr("创建人")));	
	ui.tableInfo->setItem(4, 5, new QTableWidgetItem(step.creator));

	ui.tableInfo->setItem(5, 4, new QTableWidgetItem(tr("备注")));
	ui.tableInfo->setItem(6, 5, new QTableWidgetItem(step.memo));

	//info
	m_tableHelper.updateTable(step);
}